<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新增学生</title>
<script>
function newStudent()
{
	if (window.XMLHttpRequest) 
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	     xmlhttp=new XMLHttpRequest(); 
	  } 
	else {// code for IE6, IE5 
	   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
   xmlhttp.open("post","/newstudent",true);
    xmlhttp.onreadystatechange=function ()
    { if (xmlhttp.readyState === 4) {
        if (xmlhttp.status === 200) {
            try {
                location.href="student.html";
            } catch (error) {
                console.error( error);
                alert("解析数据失败，请检查服务器返回的数据格式");
            }
        } else {
            console.error("请求失败，状态码:", xmlhttp.status, "状态文本:", xmlhttp.statusText);
            alert("查询失败");
        }
    }
    }
   xmlhttp.setRequestHeader("Content-type",
   "application/x-www-form-urlencoded");
   name=document.getElementById("name").value
   let enrollTime=document.getElementById("enrollTime").value
   let majorID=document.getElementById("majorID").value
   sex=document.getElementById("sex").value
   let sfzh=document.getElementById("sfzh").value

   xmlhttp.send("name="+name+"&enrollTime="+enrollTime+
		   "&majorID="+majorID+"&sex="+sex+"&sfzh="+sfzh);

  
  
}


</script>

</head>
<body>
    <div align="center">
    <div>
     姓名：<input type="text" id="name"><br>
     入学日期：<input type="text" id="enrollTime"><br>
     专业：<input type="text" id="majorID"><br>
     性别：<input type="text" id="sex"><br>
     身份证号：<input type="text" id="sfzh"><br>
     <button onclick="newStudent()">保存</button>
    </div>
    </div>
</body>
</html>